/**
 *  JPanel containing the dataset produced by each run
 *
 *  Copyright (c) 2009 Daniel Kornhauser.  All rights reserved.
 *  @author Daniel Kornhauser
 */

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
import org.rosuda.javaGD.GDCanvas;

// Refer to http://www.wojtek.njh6.de/Ddocs/Djri/jri.html or in the pdf docs directory
public class GDC extends  GDCanvas implements  MouseListener, MouseMotionListener{

	private static final long serialVersionUID = 1L;
	Rengine re;
	public SweepViewGui sweepViewGui;
	
	public GDC(int arg0, int arg1, Rengine r ) {
		super(arg0, arg1);
		this.addMouseMotionListener(this);
		re = r;
	}
	
	public GDC(double arg0, double arg1, Rengine r) {
		super(arg0, arg1);
		this.addMouseMotionListener(this);
		re = r;
	}
	
	public void mouseClicked(MouseEvent e) {
		//System.out.println("Clicked" + e.getX() + " " + e.getY());
    	REXP z;  	
    	z = re.eval("myClickFocus("+ e.getX() + " ," + e.getY()+")");
    	
    	//String t[]=z.asStringArray();
    	//if (t!=null) { System.out.println(java.util.Arrays.toString(t)); }
    	//if (t!=null) { System.out.println("t[0]:" + t[0] + "   t[1]:" + t[1]); }

    	//sweepViewGui.plotCell( Integer.valueOf(t[0]), Integer.valueOf(t[1]));
	}
	
	public void mouseDragged(MouseEvent e) {
	}

	public void mouseMoved(MouseEvent e) {
		//System.out.println("Moving" + e.getX() + " " + e.getY());
		REXP z;  
    	z = re.eval("myClickFocus("+ e.getX() + " ," + e.getY()+")");	
    	String t[] = null;
        if (z!=null) {t=z.asStringArray();}
        //if (z!=null) { System.out.println(java.util.Arrays.toString(t));}

		REXP x;
        x = re.eval("posClickFocus("+ e.getX() + " ," + e.getY()+")");	
        //System.out.println(x);
        String u[] = null;
        if (x!=null) {u=x.asStringArray();}
        //if (x!=null) { System.out.println("test: " + java.util.Arrays.toString(u));}
	}
}
